/*    */ package blockbuster.components.shape;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ import javax.vecmath.Vector3f;
/*    */ 
/*    */ public class BedrockComponentShapeSphere
/*    */   extends BedrockComponentShapeBase
/*    */ {
/* 16 */   public MolangExpression radius = MolangParser.ZERO;
/*    */ 
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 21 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 23 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 25 */     if (element.has("radius")) this.radius = parser.parseJson(element.get("radius"));
/*    */     
/* 27 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 33 */     JsonObject object = (JsonObject)super.toJson();
/*    */     
/* 35 */     if (!MolangExpression.isZero(this.radius)) object.add("radius", this.radius.toJson());
/*    */     
/* 37 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void apply(BedrockEmitter emitter, BedrockParticle particle) {
/* 43 */     float centerX = (float)this.offset[0].get();
/* 44 */     float centerY = (float)this.offset[1].get();
/* 45 */     float centerZ = (float)this.offset[2].get();
/* 46 */     float radius = (float)this.radius.get();
/*    */     
/* 48 */     Vector3f direction = new Vector3f((float)Math.random() * 2.0F - 1.0F, (float)Math.random() * 2.0F - 1.0F, (float)Math.random() * 2.0F - 1.0F);
/* 49 */     direction.normalize();
/*    */     
/* 51 */     if (!this.surface)
/*    */     {
/* 53 */       radius = (float)(radius * Math.random());
/*    */     }
/*    */     
/* 56 */     direction.scale(radius);
/*    */     
/* 58 */     particle.position.x = (centerX + direction.x);
/* 59 */     particle.position.y = (centerY + direction.y);
/* 60 */     particle.position.z = (centerZ + direction.z);
/*    */     
/* 62 */     this.direction.applyDirection(particle, centerX, centerY, centerZ);
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\shape\BedrockComponentShapeSphere.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */